#include <bits/stdc++.h>
#include "poly.h"
// 2025/05/15
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

int main()
{
    freopen("output.txt", "w", stdout);
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dist_ac(1, 7); // a, c: 1~6（正整数）
    uniform_int_distribution<> dist_bd(-5, 5); // b, d: -5~5

    int num_problems = 100; 
    vector<string> problems;
    vector<string> answers;

    for (int i = 1; i <= num_problems; ++i) {
        int t = dist_bd(gen);
        int a1 = dist_ac(gen), a2 = dist_ac(gen);
        int c1 = dist_ac(gen), c2 = dist_ac(gen);
        int b1 = dist_bd(gen), b2 = dist_ac(gen);
        int d1 = dist_bd(gen), d2 = dist_ac(gen);

        // 生成多项式
        poly p1({ Frac(b1, b2), Frac(a1, a2) });
        poly p2({ Frac(d1, d2), Frac(c1, c2) });
        poly p3({ Frac(t), Frac(1) });
        // 计算乘积
        poly p4 = p1 * p2;
        // 生成题目
        problems.push_back(p4.to_string());
        // 生成答案
        answers.push_back("(" + p1.to_string() + ")(" + p2.to_string() + ")");
    }

    // 输出所有习题
    cout << "Problems (Cross Multiplication Method):\n";
    for (size_t i = 0; i < problems.size(); ++i) {
        cout << "#" << (i + 1) << ": $" << problems[i] << "=$" << endl;
    }

    cout << "\nAnswers:\n";
    // 输出所有答案
    for (size_t i = 0; i < answers.size(); ++i) {
        cout << "#" << (i + 1) << ": $" << answers[i] << "$" << endl;
    }

    return 0;
}